package org.theSeed.singleSecurity.handlers;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.theSeed.base.pojo.sysEnum.SysCode;
import org.theSeed.base.pojo.vo.R;
import org.theSeed.web.utils.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 认证异常处理（用户为登录或token过期）
 */
@Slf4j
public class SeedAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ResponseUtil.writeResponse(response, R.fail(SysCode.UN_AUTH));
    }
}
